package com.learning.seata.demo.service.impl;

import com.learning.seata.demo.dao.OrderDAO;
import com.learning.seata.demo.model.Order;
import com.learning.seata.demo.service.AccountService;
import com.learning.seata.demo.service.OrderService;

/**
 * ClassName: OrderServiceImpl
 * Description: 仓储服务：对给定的商品扣除仓储数量。
 * Date: 2021/3/12 13:56 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
public class OrderServiceImpl implements OrderService {

    private OrderDAO orderDAO;

    private AccountService accountService;

    @Override
    public Order create(String userId, String commodityCode, int orderCount) {

        int orderMoney = calculate(commodityCode, orderCount);

        accountService.debit(userId, orderMoney);

        Order order = new Order();
        order.userId = userId;
        order.commodityCode = commodityCode;
        order.count = orderCount;
        order.money = orderMoney;

        // INSERT INTO orders ...
        return orderDAO.insert(order);
    }

    private int calculate(String commodityCode, int orderCount) {
        return 0;
    }
}